/*
 * © Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 *    
 */

package org.vineatoum.view.data;

import javax.swing.JPanel;

import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;

import org.vineatoum.business.Cuve;
import org.vineatoum.business.configuration.CuveType;
import org.vineatoum.model.abstraction.IVineaToumModel;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

public class CuveDataPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6779005200522265769L;
	private JTextField textFieldName;
	private JSpinner spinnerSize;
	private JComboBox comboBoxKind;
	private JCheckBox checkBoxChapeauFlottant;

	/**
	 * Create the panel.
	 * @param model 
	 */
	public CuveDataPanel(IVineaToumModel model, Cuve cuve) {
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 0, 0, 0, 0, 0, 0 };
		gbl_panel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
		gbl_panel.columnWeights = new double[] { 0.0, 1.0, 1.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 1.0,
				Double.MIN_VALUE };
		setLayout(gbl_panel);
		{
			JLabel lblName = new JLabel("Nom");
			GridBagConstraints gbc_lblName = new GridBagConstraints();
			gbc_lblName.insets = new Insets(0, 0, 5, 5);
			gbc_lblName.anchor = GridBagConstraints.EAST;
			gbc_lblName.gridx = 0;
			gbc_lblName.gridy = 0;
			add(lblName, gbc_lblName);
		}
		{
			setTextFieldName(new JTextField(cuve.getName()));
			GridBagConstraints gbc_textField = new GridBagConstraints();
			gbc_textField.insets = new Insets(0, 0, 5, 5);
			gbc_textField.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField.gridx = 1;
			gbc_textField.gridy = 0;
			add(getTextFieldName(), gbc_textField);
			getTextFieldName().setColumns(10);
		}
		{
			JLabel lblSize = new JLabel("Taille");
			GridBagConstraints gbc_lblSize = new GridBagConstraints();
			gbc_lblSize.insets = new Insets(0, 0, 5, 5);
			gbc_lblSize.anchor = GridBagConstraints.EAST;
			gbc_lblSize.gridx = 0;
			gbc_lblSize.gridy = 1;
			add(lblSize, gbc_lblSize);
		}
		{
			setSpinnerSize(new JSpinner());
			getSpinnerSize().setModel(new SpinnerNumberModel(new Float(0), new Float(0), new Float(99999), new Float(1.5)));
			getSpinnerSize().setValue(cuve.getSize());
			GridBagConstraints gbc_textField = new GridBagConstraints();
			gbc_textField.insets = new Insets(0, 0, 5, 5);
			gbc_textField.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField.gridx = 1;
			gbc_textField.gridy = 1;
			add(getSpinnerSize(), gbc_textField);
		}
		{
			JLabel lblType = new JLabel("Type");
			GridBagConstraints gbc_lblType = new GridBagConstraints();
			gbc_lblType.anchor = GridBagConstraints.EAST;
			gbc_lblType.insets = new Insets(0, 0, 5, 5);
			gbc_lblType.gridx = 0;
			gbc_lblType.gridy = 2;
			add(lblType, gbc_lblType);
		}
		{
			setComboBoxKind(new JComboBox());
			List<CuveType> data = new ArrayList<CuveType>();
			for (Iterator<CuveType> iterator = CuveType.cuveTypes.iterator(); iterator
					.hasNext();) {
				CuveType type = (CuveType) iterator.next();
				if (type.getName() != null && !type.getName().isEmpty()) {
					data.add(type);
				}
			}
			getComboBoxKind().setModel(new DefaultComboBoxModel(data.toArray()));
			getComboBoxKind().setSelectedItem(cuve.getKind());
			GridBagConstraints gbc_comboBox = new GridBagConstraints();
			gbc_comboBox.insets = new Insets(0, 0, 5, 5);
			gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
			gbc_comboBox.gridx = 1;
			gbc_comboBox.gridy = 2;
			add(getComboBoxKind(), gbc_comboBox);
		}
		{
			JLabel lblChapeauFlottant = new JLabel("Chapeau Flottant");
			GridBagConstraints gbc_lblType = new GridBagConstraints();
			gbc_lblType.anchor = GridBagConstraints.EAST;
			gbc_lblType.insets = new Insets(0, 0, 5, 5);
			gbc_lblType.gridx = 0;
			gbc_lblType.gridy = 3;
			add(lblChapeauFlottant, gbc_lblType);
		}
		{
			setCheckBoxChapeauFlottant(new JCheckBox());
			getCheckBoxChapeauFlottant().setSelected(cuve.isChapeauFlottant());
			GridBagConstraints gbc_textField = new GridBagConstraints();
			gbc_textField.insets = new Insets(0, 0, 5, 5);
			gbc_textField.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField.gridx = 1;
			gbc_textField.gridy = 3;
			add(getCheckBoxChapeauFlottant(), gbc_textField);
		}
	}

	/**
	 * @param textFieldName the textFieldName to set
	 */
	public void setTextFieldName(JTextField textFieldName) {
		this.textFieldName = textFieldName;
	}

	/**
	 * @return the textFieldName
	 */
	public JTextField getTextFieldName() {
		return textFieldName;
	}

	/**
	 * @param comboBoxKind the comboBoxKind to set
	 */
	public void setComboBoxKind(JComboBox comboBoxKind) {
		this.comboBoxKind = comboBoxKind;
	}

	/**
	 * @return the comboBoxKind
	 */
	public JComboBox getComboBoxKind() {
		return comboBoxKind;
	}

	/**
	 * @param checkBoxChapeauFlottant the checkBoxChapeauFlottant to set
	 */
	public void setCheckBoxChapeauFlottant(JCheckBox checkBoxChapeauFlottant) {
		this.checkBoxChapeauFlottant = checkBoxChapeauFlottant;
	}

	/**
	 * @return the checkBoxChapeauFlottant
	 */
	public JCheckBox getCheckBoxChapeauFlottant() {
		return checkBoxChapeauFlottant;
	}

	/**
	 * @param spinnerSize the spinnerSize to set
	 */
	public void setSpinnerSize(JSpinner spinnerSize) {
		this.spinnerSize = spinnerSize;
	}

	/**
	 * @return the spinnerSize
	 */
	public JSpinner getSpinnerSize() {
		return spinnerSize;
	}

}
